package com.saturday.common.exception;

import com.saturday.common.constants.ResultConsts;
import lombok.Data;

import java.io.Serializable;

/**
 * 当用户信息缺失或者无法获取时抛出该异常
 */
@Data
public class UserContextLoseException extends RuntimeException implements Serializable {

    public static final String FAIL_CODE = String.valueOf(ResultConsts.NOT_LOGIN);

    private String code;

    private String message;

    public UserContextLoseException(String message) {
        super(message);
        this.code = FAIL_CODE;
        this.message = message;
    }

    public UserContextLoseException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public static UserContextLoseException createException(String message) {
        return new UserContextLoseException(message);
    }

    @Deprecated
    public static UserContextLoseException createException(String code, String message) {
        return new UserContextLoseException(code, message);
    }

    public static UserContextLoseException createException() {
        return new UserContextLoseException("登录已过期，请重新登录");
    }
}
